<template>
  <el-card class="content-card schedule-card">
    <template #header>
      <div class="card-header">
        <span>近期安排</span>
      </div>
    </template>
    <div class="schedule-list">
      <div
        class="schedule-item"
        v-for="(item, index) in scheduleData"
        :key="index"
        @click="goToPage(`/oa/schedule/view?id=${item.id}`)"
      >
        <div class="schedule-time">{{ item.start_time_format }}</div>
        <div class="schedule-content">{{ item.content }}</div>
      </div>
      <div v-if="scheduleData.length === 0" class="no-data">暂无安排</div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
  import { useRouter } from 'vue-router'
  import { ElMessage } from 'element-plus'

  interface ScheduleItem {
    id: string | number
    start_time_format: string
    content: string
  }

  interface Props {
    scheduleData: ScheduleItem[]
  }

  const props = defineProps<Props>()
  const router = useRouter()

  // 跳转到指定页面
  const goToPage = (url: string) => {
    if (url) {
      router.push(url).catch(err => {
        ElMessage.error('页面跳转失败')
        console.error('页面跳转失败:', err)
      })
    }
  }
</script>

<style scoped>
  /* 近期安排样式 */
  .content-card {
    height: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: none;
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
  }

  .schedule-card {
    margin-top: 20px;
  }

  .schedule-list {
    min-height: auto;
  }

  .schedule-item {
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.3s ease;
  }

  .schedule-item:hover {
    background-color: #f8f9fa;
    padding-left: 8px;
  }

  .schedule-item:last-child {
    border-bottom: none;
  }

  .schedule-time {
    font-size: 12px;
    color: #999;
    margin-bottom: 4px;
  }

  .schedule-content {
    font-size: 14px;
    color: #333;
    font-weight: 500;
  }

  .no-data {
    text-align: center;
    padding: 20px 0;
    color: #999;
    font-size: 14px;
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .schedule-list {
      min-height: 180px;
    }

    .schedule-item {
      padding: 10px 0;
    }

    .schedule-time {
      font-size: 11px;
    }

    .schedule-content {
      font-size: 13px;
    }
  }
</style>
